#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <fcntl.h>
#include <unistd.h>

#include "queue.h"
#include "cJSON.h"

int main(int argc, char **argv)
{
	if (argc < 3) {
		printf("usag:sendmsg queue_name msg\n");
		return 0;
	}
	int priority = 0;
	if (argc > 3) {
		priority = 1;
	}
	send_msg(argv[1], argv[2], strlen(argv[2]), 0, priority);
	perror("send_msg");
	char buf[1024 * 8];
	if (timerecv_msg(SERVICE_QUEUE_RSP, buf, sizeof(buf), 1) > 0) {
		cJSON *json = cJSON_Parse(buf);
		char *ptr = cJSON_Print(json);
		printf("%s\n", ptr);
	}
	return 0;
}